package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
             ){
            String sql = "SELECT s.name,s.gender,s.age,s.job,c.name,c.floor "+
                    "FROM class c "+
                    "JOIN student ON c.id = s.class_id "+
                    "WHERE c.name = '1年级1班'";
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                String sName = rs.getString("name");
                String sGender = rs.getString("gender");
                int sAge = rs.getInt("age");
                String sJob = rs.getString("job");
                String cName = rs.getString("c.name");
                int cFloor = rs.getInt("c.floor");
                System.out.println(sName+" "+sGender+" "+sAge+" "+sJob+" "+cName+" "+cFloor);


            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
